<template>
  <div class="counter_container">
    <button class="subBtn" @click="sub">-</button>
    <span class="num">{{ num_c }}</span>
    <button class="addBtn" @click="add">+</button>
  </div>
</template>
<script>
export default {
  props: {
    num_c: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    sub() {
      if (this.num_c > 0) {
        this.$emit("amount-change", this.num_c - 1);
      }
    },
    add() {
      this.$emit("amount-change", this.num_c + 1);
    },
  },
};
</script>
<style lang="less">
.counter_container {
  display: flex;
  align-items: center;
  height: 40px;
  button {
    border: 0;
    border-radius: 3px;
    width: 30px;
    height: 30px;
    background-color: #f7f8f9;
  }
  .num {
    display: inline-block;
    width: 50px;
    height: 30px;
    text-align: center;
    line-height: 30px;
  }
}
</style>